package cn.lccabc.user.controller;

import cn.lccabc.user.entity.User;
import cn.lccabc.user.service.UserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;

/**
 * Created by L on 2018/4/8.
 */
@Controller
@RequestMapping(value = "user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "info")
    @ResponseBody
    public User getUserInfo(HttpSession session){
        User userInfo = (User) session.getAttribute("userinfo");
        return userInfo;
    }

    @RequestMapping(value = "creat")
    @ResponseBody
    public String creatUser(@RequestBody User user) throws Exception {
        userService.creatUser(user);
        return "succeed";
    }

    @RequiresPermissions("attend:attendList")
    @RequestMapping(value = "infos")
    @ResponseBody
    public User getUserShiro(){
        User userShiro = userService.findByUsernameShiro("laowang666");
        return userShiro;
    }

}
